<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>财务统计报表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>
    财务管理
    <span class="c-gray en">&gt;</span>
    财务统计
</nav>
<div class="page-container">
    <div class="mt-20">
        <div class="mb-10 mt-10">
            <form class="form-inline" id="merchantStatisticalForm">
                <div class="form-group">
                    <label class="control-label" title="">
                        开始时间：
                    </label>
                    <input id="merchantStatisticalTimeStart" type="text" onfocus="WdatePicker()"
                           readonly="readonly" class="form-control Wdate" style="width:150px;">
                </div>
                <div class="form-group">
                    <label class="control-label" title="">
                        结束时间：
                    </label>
                    <input id="merchantStatisticalTimeEnd" name="addTimeEnd" type="text" onfocus="WdatePicker()"
                           readonly="readonly" class="form-control Wdate" style="width:150px;">
                </div>
                <span onclick="merchantFinanceStatistical.searchAction();" class="btn btn-default">查询 <i class="glyphicon glyphicon-search"></i></span>
            </form>
        </div>
        <div class="col-xs-12">
            <div style="background: #eeeeeed4;border-radius: 4px;-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.05);box-shadow: 0 1px 1px rgba(0,0,0,.05);">
                <div id="merchant-statistical-chart" style="width: 100%;height: 650px"></div>
            </div>
        </div>
    </div>
</div>
<script>
    var merchantFinanceStatistical = {
        myChart: echarts.init($("#merchant-statistical-chart")[0]),
        getOption : function (myData) {
            let _this = this;
            let waterMarkText = '统计报表';
            let canvas = document.createElement('canvas');
            let ctx = canvas.getContext('2d');
            canvas.width = canvas.height = 100;
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            ctx.globalAlpha = 0.1;
            ctx.font = '20px Microsoft Yahei';
            ctx.translate(50, 50);
            ctx.rotate(-Math.PI / 4);
            ctx.fillText(waterMarkText, 0, 0);
            let option = {
                backgroundColor: {
                    type: 'pattern',
                    image: canvas,
                    repeat: 'repeat'
                },
                tooltip: {},
                title: [{
                    text: '商户旗下各门店营业额',
                    x: '25%',
                    y : "10px",
                    textAlign: 'center'
                }, {
                    text: '各门店营业额占比',
                    x: '75%',
                    y:"10px",
                    textAlign: 'center'
                }],
                grid: [{
                    top: 50,
                    width: '50%',
                    bottom: '10px',
                    left: 10,
                    containLabel: true
                }],
                xAxis: [{
                    type: 'value',
                    splitLine: {
                        show: false
                    }
                }],
                yAxis: [{
                    type: 'category',
                    data: Object.keys(myData),
                    axisLabel: {
                        interval: 0,
                        rotate: 30
                    },
                    splitLine: {
                        show: false
                    }
                }],
                series: [{
                    type: 'bar',
                    stack: 'chart',
                    z: 3,
                    label: {
                        normal: {
                            position: 'right',
                            show: true
                        }
                    },
                    data: Object.keys(myData).map(function (key) {
                        return myData[key];
                    })
                }, {
                    type: 'pie',
                    radius: [0, '55%'],
                    center: ['75%', '50%'],
                    data: Object.keys(myData).map(function (key) {
                        return {
                            name: key.replace('.js', ''),
                            value: myData[key]
                        }
                    })
                }]
            };
            return option;
        },
        init: function () {
            let _this = this;
            //设置页面初次加载时，时间控件所显示的时间
            var addTimeStart = _this.time(-1);
            var addTimeEnd = _this.time(0);
            $("#merchantStatisticalTimeStart").val(addTimeStart);
            $("#merchantStatisticalTimeEnd").val(addTimeEnd);

            //根据商户，获取总收入
            $.ajax({
                type: "GET",
                url: 'order/getPayAmountByBizId?addTimeStart=' + addTimeStart + "&addTimeEnd=" + addTimeEnd,
                dataType: "json",
                async: false,
                success: function (data) {
                    _this.myChart.setOption(_this.getOption(data.data));
                },
                error: function () {
                    alert("error");
                }
            });

        },
        //查询
        searchAction: function () {
            let _this = this;
            var addTimeStart = $("#merchantStatisticalTimeStart").val();
            var addTimeEnd = $("#merchantStatisticalTimeEnd").val();
            $.ajax({
                type: "get",
                url: 'order/getPayAmountByBizId?addTimeStart=' + addTimeStart + "&addTimeEnd=" + addTimeEnd,
                data: $("#merchantStatisticalForm").serialize(),
                dataType: "json",
                async: false,
                success: function (json) {
                    _this.myChart.clear();
                    _this.myChart.setOption(_this.getOption(json.data));
                },
                error: function () {
                    alert("error");
                }
            });
        },
        //获取时间的方法
        time: function (index) {
            var today = new Date();
            today.setMonth(today.getMonth() + index);
            var h = today.getFullYear();
            var m = today.getMonth() + 1;
            var d = today.getDate();
            m = m < 10 ? "0" + m : m;
            d = d < 10 ? "0" + d : d;
            return h + "-" + m + "-" + d;
        }
    };

    merchantFinanceStatistical.init();

</script>
</body>
</html>